package com.easycoding.framework.context;

import java.util.HashMap;
import java.util.Map;

/**
 * <b>Description</b>:<br/>
 * <b>Create Date</b>: 2013-3-8 下午5:32:33<br/>
 * <b>Version</b>: Since JDK 1.6.0<br/>
 * <b>Package</b>: com.easycoding.easyweb.framework.context
 */
public class WebContext {
	/*** 对象保持者*/
	private Map<String, Object> keeper = new HashMap<String, Object>();
	
	private static ThreadLocal<WebContext> currentInstance = new ThreadLocal<WebContext>(){
		protected WebContext initialValue(){
			WebContext context = new WebContext();
			return context;
		}
	};
	/**
	 * 初始化
	 */
	public static void init(){
		WebContext context = new WebContext();
		currentInstance.set(context);
	}
	
	/**
	 * 消毁上下文
	 */
	public static void destory(){
		currentInstance.set(null);
	}
	
	/**
	 * 当前用户的上下文
	 * @return
	 */
	public static WebContext currentContext(){
		return currentInstance.get();
	}


	public Map<String, Object> getKeeper() {
		return keeper;
	}
	
}
